<template>
    <div>
        <div class="con1">
            <el-form :inline="true" class="demo-form-inline">
                <el-form-item label="病历号" >
                    <el-input v-model="caseNumber" placeholder="请输入病历号..."></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="onSubmit">查询</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button @click="today" type="success">今日处理情况</el-button>
                </el-form-item>
            </el-form>
            <el-divider></el-divider>
        </div>
        <div class="con2">
            <el-table
                    :data="tableData"
                    style="width: 100%">
                <el-table-column type="expand">
                    <template slot-scope="props">
                        <el-card>
                        <el-table class="flag"  row-class-name="row" header-row-class-name="row"
                                :data="props.row.checkApplyList"
                                style="width: 100%">
                            <el-table-column
                                    prop="name"
                                    label="检查项目"
                                    width="180">
                            </el-table-column>
                            <el-table-column
                                    prop="objective"
                                    label="检查目的"
                                    >
                            </el-table-column>
                            <el-table-column
                                    prop="position"
                                    label="检查位置"
                                    >
                            </el-table-column>
                            <el-table-column
                                    prop="creationTime"
                                    label="开方时间"
                                    :formatter="formatter"
                            >
                            </el-table-column>
                            <el-table-column
                                    prop="state"
                                    label="状态"
                                    :formatter="formatter1"
                            >
                            </el-table-column>
                            <el-table-column
                                    fixed="right"
                                    label="操作">
                                <template slot-scope="scope">
                                    <el-button @click="pay(scope.row)" type="info" size="small"
                                               :disabled="scope.row.state >=3 ? true: false">交费
                                    </el-button>
                                    <el-button @click="payDel(scope.row)" type="info" size="small"
                                               :disabled="scope.row.state !=3 ? true: false">退费
                                    </el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                        </el-card>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="caseNumber"
                        label="病历号"
                        width="180">
                </el-table-column>
                <el-table-column
                        prop="realName"
                        label="姓名"
                        width="180">
                </el-table-column>
                <el-table-column
                        prop="age"
                        label="年龄"
                        width="180"
                        :formatter="formatter2">
                </el-table-column>
                <el-table-column
                        prop="gender"
                        label="性别"
                        width="180"
                        :formatter="formatter3">
                </el-table-column>
                <el-table-column
                        prop="registLeID"
                        label="挂号级别"
                        width="180">
                    <template slot-scope="scope">
                        <el-tag :type="scope.row.registLeID == '1' ? 'primary' : 'danger'"
                                size="small" plain>
                            {{scope.row.registLeID==1?'普通':'专家'}}
                        </el-tag>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="registTime"
                        label="挂号日期"
                        width="180"
                        :formatter="formatter">
                </el-table-column>
                <el-table-column
                        prop="visitState"
                        label="看诊状态"
                >
                    <template slot-scope="scope">
                        <el-tag :type="scope.row.visitState == '4' ? 'danger' : 'primary'"
                                size="small" plain>
                            {{scope.row.visitState==1?'已挂号':scope.row.visitState==2?'正接诊':scope.row.visitState==3?'已看诊':scope.row.visitState==4?'已退号':'已失效'}}
                        </el-tag>
                    </template>
                </el-table-column>

            </el-table>
        </div>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                caseNumber: '',
                tableData: []
            }
        },
        created() {
            this.$ajax.get("http://localhost:8082/queryTodayCheck").then((res) => {
                this.tableData = res.data
            })
        },
        methods: {
            today(){
                this.$ajax.get("http://localhost:8082/queryTodayCheck").then((res) => {
                    this.tableData = res.data
                })
            },
            pay(row){
                row.state=3
                this.$ajax.post("http://localhost:8082/updateById",row).then((res) => {
                    if(res.data="success") this.$message("收费成功")
                    else this.$message("收费失败")
                })

            },
            payDel(row){
                row.state=6
                this.$ajax.post("http://localhost:8082/updateById",row).then((res) => {
                    if(res.data="success") this.$message("退费成功")
                    else this.$message("退费失败")
                })
            },
            onSubmit() {
                this.$ajax.get(`http://localhost:8082/queryOne?caseNumber=${this.caseNumber}`).then((res) => {
                    this.tableData = res.data
                })
            },
            formatter3(row, column) {
                let sex = row.gender;
                if (sex == 71) return '男'
                else
                    return '女';
            },
            formatter1(row,column){
                switch (row.state) {
                    case 1:
                        return "暂存";
                    case 2:
                        return "已开立"
                    case 3:
                        return "已交费"
                    case 4:
                        return "已登记"
                    case 5:
                        return "执行完"
                    case 6:
                        return "已退费"
                    case '0':
                        return "已作废"
                }

            },
            formatter2(row, column) {
                let age = row.age + row.ageType;
                return age;
            },
            formatter(row, column) {
                let d = new Date(row[column.property]);
                let year = d.getFullYear();
                let month = d.getMonth();
                let day = d.getDate();
                let hour = d.getHours();
                let minute = d.getMinutes();
                let s = year + "-" + this.format(month + 1) + "-" + this.format(day) + " " + this.format(hour) + ":" + this.format(minute)
                return s
            },
            format(d) {
                return d > 9 ? d : '0' + d;
            },
        }
    }
</script>

<style>
    .con1 {
        text-align: center;
    }
    .row{
        color: #272a69;
    }
</style>